package site.overview.action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import modules.recruit.service.TownService;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.guinea.core.orm.Page;
import com.guinea.core.orm.PropertyFilter;
import com.guinea.core.service.EntityService;
import com.guinea.core.utils.ServletUtils;
import com.guinea.core.web.StrutsAction;
import com.guinea.core.web.StrutsSimpleAction;

public class TownActionSite extends StrutsSimpleAction {

	private TownService townService;

	public EntityService getEntityService() {
		return townService;
	}
	
	public TownService getTownService() {
		return townService;
	}

	public void setTownService(TownService townService) {
		this.townService = townService;
	}
	/**
	 * url参数未定义method时的默认Action函数. 默认为index Action.
	 */
	public ActionForward unspecified(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		return list(mapping, form, request, response);
	}
	/**
	 * 列出所有对象的Action函数.
	 */
	public ActionForward list(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		// 从request中获取含属性前缀名的参数,构造去除前缀名后的参数Map.
		Map filterParamMap = ServletUtils.getParametersStartingWith(request,
				FILTER_PREFIX + "_");
		List filters = PropertyFilter.buildFromParaMap(filterParamMap);
		Page page = PropertyFilter.buildPageFromHttpRequest(request,
				REQUEST_PAGE);

		page = getTownService().findPage(page, filters);

		request.setAttribute(REQUEST_PAGE, page);
		request.setAttribute(FILTER_MAP, filterParamMap);
		return mapping.findForward("list");
	}
}
